package org.openmore.consumer.controller.api;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.openmore.common.exception.InvalidParamsException;
import org.openmore.consumer.annotation.TokenAuthCheck;
import org.openmore.consumer.controller.common.BaseController;
import org.openmore.consumer.dto.common.BaseResponse;
import org.openmore.consumer.dto.common.Pagination;
import org.openmore.consumer.dto.common.TenantDto;
import org.openmore.consumer.entity.enums.TenantStatus;
import org.openmore.consumer.service.feign.TenantService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

/**
 * THIS IS AUTO GENERATED SOURCE CODE
 *   Created by org.openmore
 *      on 2020-03-16
*/
@Api(value = "/Tenant", tags = "", description = "")
@RequestMapping(value = "/api/tenant", produces = {APPLICATION_JSON_UTF8_VALUE})
@RestController
public class TenantController extends BaseController {
     private Logger logger = LoggerFactory.getLogger(this.getClass());

     @Autowired
     private TenantService tenantService;

     @TokenAuthCheck
     @ApiOperation(value = "分页返回所有数据", response = TenantDto.class, responseContainer = "List")
     @ApiResponses(value = { @ApiResponse(code = 400, message = "请求失败：找不到id={id}的", response = BaseResponse.class) })
     @RequestMapping(method = RequestMethod.GET, value = "/query")
     public BaseResponse selectAllByPage(@RequestParam(required = false) @ApiParam(value = "创建者ID") String userId,
                                         @RequestParam(required = false) @ApiParam(value = "名称") String name,
                                         @RequestParam(required = false) @ApiParam(value = "应用状态") TenantStatus status,
                                         @RequestParam(required = false) @ApiParam(value = "创建时间") Date createdTimeStart,
                                         @RequestParam(required = false) @ApiParam(value = "创建时间") Date createdTimeEnd,
                                         @RequestParam(required = false, defaultValue = "1") @ApiParam(value = "分页第几页") Integer pageNum,
                                        @RequestParam(required = false, defaultValue = "10") @ApiParam(value = "每页多少记录") Integer pageSize)
     {
          logger.debug(">> selectAllByPage");
          return tenantService.selectAllByPage(userId, name, status, createdTimeStart, createdTimeEnd, pageNum, pageSize);
     }

     @TokenAuthCheck
     @ApiOperation(value = "根据id获取信息", response = TenantDto.class)
     @ApiResponses(value = { @ApiResponse(code = 400, message = "请求失败：找不到id={id}的", response = BaseResponse.class) })
     @RequestMapping(method = RequestMethod.GET, value = "/{id}")
     public BaseResponse getTenantById(@PathVariable @ApiParam(required = true, value = "id") String id){
        logger.debug(">> getTenantById");
        return tenantService.getTenantById(id);
     }

     @TokenAuthCheck
     @ApiOperation("更新")
     @ApiResponses(value = { @ApiResponse(code = 400, message = "请求失败：更新的数据不存在", response = BaseResponse.class),
                             @ApiResponse(code = 400, message = "请求失败：数据更新失败", response = BaseResponse.class) })
     @RequestMapping(method = RequestMethod.PUT)
     public BaseResponse updateTenant(@RequestBody @ApiParam(value = "新信息", required = true) TenantDto tenant)
     {
        logger.debug(">> updateTenant");
        return tenantService.updateTenant(tenant);

     }

     @TokenAuthCheck
     @ApiOperation("创建")
     @ApiResponses(value = { @ApiResponse(code = 400, message = "请求失败：数据创建失败", response = BaseResponse.class) })
     @RequestMapping(method = RequestMethod.POST, consumes = {APPLICATION_JSON_UTF8_VALUE})
     public BaseResponse insertTenant(@RequestBody @ApiParam(value = "创建", required = true) TenantDto tenant){
          logger.debug(">> insertTenant");
        return tenantService.insertTenant(tenant);
     }

     @TokenAuthCheck
     @ApiOperation(value = "删除指定")
     @ApiResponses(value = { @ApiResponse(code = 400, message = "请求失败：数据删除失败", response = BaseResponse.class) })
     @RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
     public BaseResponse deleteTenant(@PathVariable @ApiParam(value = "id", required = true) String id)
     {
        logger.debug(">> deleteTenant");
        return tenantService.deleteTenant(id);
     }
}




